package com.gz.university.crm.web.action;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.ServletContext;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.gz.university.crm.entity.SysMenu;
import com.gz.university.crm.service.ISysMenuPrivilegeService;
import com.gz.university.crm.service.ISysMenuService;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
@ParentPackage("basePackage")
@Namespace("/")
@Action(value = "menuAction")
@Results({ @Result(name = "top", location = "/WEB-INF/page/menu/top.jsp"),
		@Result(name = "left", location = "/WEB-INF/page/menu/left.jsp") })
public class MenuAction extends BaseAction {
    private ISysMenuPrivilegeService sysMenuPrivilegeService;//获取菜单权限
    private ISysMenuService sysMenuService;//获取菜单功能的
    
	public ISysMenuPrivilegeService getSysMenuPrivilegeService() {
		return sysMenuPrivilegeService;
	}
    @Resource(name=ISysMenuPrivilegeService.SERVICE_NAME)
	public void setSysMenuPrivilegeService(
			ISysMenuPrivilegeService sysMenuPrivilegeService) {
		this.sysMenuPrivilegeService = sysMenuPrivilegeService;
	}

	public ISysMenuService getSysMenuService() {
		return sysMenuService;
	}
    @Resource(name=ISysMenuService.SERVICE_NAME)
	public void setSysMenuService(ISysMenuService sysMenuService) {
		this.sysMenuService = sysMenuService;
	}

	public String top() {
		return "top";
	}

	public String left() {
		//查询所有的菜单
		List<SysMenu> sysMenus=this.sysMenuService.findAllSysMenus();
		ServletContext sc=ServletActionContext.getServletContext();//会一直存在在服务器中
		sc.setAttribute("sysMenus", sysMenus);
		return "left";
	}
}
